const { Queue } = require("dynamic-queue");

var outs = [];
let queue = new Queue();
let resource = null;

let t1 = (next) => {
    if (!resource) {
        setTimeout($ => {
            console.log("wait 3s ,fill resource");
            resource = 3;
            queue
            next();
        }, 3000);
    } else {
        console.log("resource is ",resource);
        setTimeout($ => {
            console.log("wait 3s");
            queue
            next();
        }, 3000);
    }
};

let t2 = (r => {
    if (resource) {
        console.log("resource is ",resource);
        setTimeout($ => {
            console.log("wait 2s");
            r(queue);
        }, 2000);
    } else {
        setTimeout($ => {
            console.log("wait 2s,fill resource");
            resource = 2;
            r(queue);
        }, 2000);
    }

})

queue.push(t2);
queue.push(t1);
console.log("start!");